<template>
	<view class="container">
		<view class="backBox" @click="backFn"><image src="@/static/back-pre.png" mode="aspectFill"></image></view>
		<image v-if="detail.type" :src="require('@/static/list'+detail.type+'.png')" mode="widthFix" class="bgPic"></image>
		<view class="mainBox" v-if="detail.reportFileList">
			<view class="mainBoxItem" v-for="(item,value) in detail.reportFileList" :key="value" @click="toDetailFn(item)">
				<image :src="require('@/static/type'+detail.type+'.png')" class="itempic" mode="widthFix"></image>
				<view class="itemRightBox">
					<view class="reportTit">
						{{item.title}}
					</view>
					<view class="timeBox">
						<image src="@/static/watch.png" mode="widthFix"></image>
						<view class="numBox">{{item.lookNum}}</view>
						<image src="@/static/down.png" mode="widthFix"></image>
						<view class="numBox">{{item.downloadNum}}</view>
						<view class="time">{{item.pushTime.replace(' 00:00:00','')}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="sureBox" v-if="!isMyself">
			<view class="price">￥ {{detail.amount?detail.amount:'0'}}</view>
			<view class="sureBtn" @click="sureFn">立即订阅</view>
		</view>
		<view class="sureBox" v-if="isMyself">
			<view class="addBtn" @click="addFn">发布新报告</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detail:{},
				id:'',
				isMyself:false,
			}
		},
		onLoad(e) {
			this.id = e.id
			if(e.isMyself){
				this.isMyself = e.isMyself
			}
		},
		onShow() {
			this.initFn()
			
		},
		methods: {
			initFn(){
				this.$http('/api/report/queryById',{id:this.id}).then(res=>{
					this.detail = res.result
				})
			},
			sureFn(){
				if(this.$isLogin)return
				if(this.detail.amount){
					uni.showToast({
						title:'暂不支持在线支付',
						icon:'none'
					})
				}else {
					this.$http('/api/order/createOrder',{reportId:this.id,totalFee:0},'POST').then(res=>{
						uni.navigateTo({
							url:'/pages/space/list'
						}).then(res1=>{
							uni.showToast({
								title:'订阅成功',
								icon:'none'
							})
						})
					})
				}
			},
			toDetailFn(item){
				uni.navigateTo({
					url:'/pages/space/detail?id='+item.id+'&reportId='+this.id+(this.isMyself?'&isMyself=true':'')
				})
			},
			backFn(){
				uni.navigateBack()
			},
			addFn(){
				uni.navigateTo({
					url:'/pages/space/addReport?reportId='+this.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 750rpx;
		.backBox {
			position: fixed;
			z-index: 99;
			top: 60rpx;
			left: 32rpx;
			width: 60rpx;
			height: 60rpx;
			border-radius: 100%;
			background: rgba(255,255,255,0.6);
			padding: 6rpx 10rpx;
			image {
				width: 36rpx;
				height: 28rpx;
			}
		}
		.bgPic {
			width: 750rpx;
			height: 0;
		}
		.mainBox {
			padding: 32rpx 32rpx 150rpx;
			background: #F6F6F6;
			border-radius: 32rpx 32rpx 0rpx 0rpx;
			margin-top: -32rpx;
			position: relative;
			z-index: 1;
			.mainBoxItem {
				background: #FFFFFF;
				border-radius: 20rpx;
				padding: 28rpx;
				margin-bottom: 16rpx;
				display: flex;
				.itempic {
					width: 120rpx;
					min-width: 120rpx;
					height: 0;
					margin-right: 28rpx;
				}
				.itemRightBox {
					width: 100%;
					padding-top: 10rpx;
					.reportTit {
						font-size: 28rpx;
						color: #1F2937;
						font-weight: bold;
						margin-bottom: 56rpx;
						line-height: 28rpx;
						min-height: 56rpx;
						text {
							font-size: 16rpx;
							padding: 4rpx 10rpx;
							font-weight: normal;
							border-radius: 6rpx;
							margin-left: 16rpx;
						}
					}
					.timeBox {
						display: flex;
						align-items: center;
						justify-content: flex-start;
						font-size: 24rpx;
						color: #9CA3AF;
						image {
							width: 26rpx;
							height: 0;
						}
						.numBox {
							margin: 0 26rpx 0 10rpx;
						}
						.time {
							margin-left: auto;
						}
					}
				}
			}
		}
		.sureBox {
			width: 750rpx;
			height: 146rpx;
			background: #FFFFFF;
			position: fixed;
			bottom: 0;
			left: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			padding-bottom: 40rpx;
			z-index: 999;
			box-shadow: 0rpx -2rpx 0rpx 0rpx rgba(0,0,0,0.06);
			.sureBtn {
				width: 272rpx;
				height: 96rpx;
				background: #2563EB;
				border-radius: 506rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 36rpx;
				color: #FFFFFF;
				position: absolute;
				top: 20rpx;
				right: 32rpx;
			}
			.addBtn {
				width: 686rpx;
				height: 96rpx;
				background: #2563EB;
				border-radius: 506rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 36rpx;
				color: #FFFFFF;
				position: absolute;
				top: 20rpx;
				right: 32rpx;
			}
			.price {
				color: #F5222D;
				font-size: 46rpx;
				position: absolute;
				top: 32rpx;
				left: 32rpx;
			}
		}
	}
</style>
